﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ariregistri_toimik_otsus", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(AriregistriToimikOtsus))]
    public class AriregistriToimikOtsusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IAriregistriToimikOtsus clazz;
        
        public AriregistriToimikOtsusSerializer(IAriregistriToimikOtsus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("otsuse_number");
            if (clazz.OtsuseNumber!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OtsuseNumber))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OtsuseNumber");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("otsuse_kpv");
            if (clazz.OtsuseKpv!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.OtsuseKpv))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("otsuse_liik");
            if (clazz.OtsuseLiik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OtsuseLiik))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("otsuse_liik_tekstina");
            if (clazz.OtsuseLiikTekstina!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OtsuseLiikTekstina))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("otsuse_olek");
            if (clazz.OtsuseOlek!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OtsuseOlek))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("otsuse_olek_tekstina");
            if (clazz.OtsuseOlekTekstina!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OtsuseOlekTekstina))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("joust_kpv");
            if (clazz.JoustKpv!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.JoustKpv))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kande_kpv");
            if (clazz.KandeKpv!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.KandeKpv))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("lisatahtaeg");
            if (clazz.Lisatahtaeg!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Lisatahtaeg))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kandeliik");
            if (clazz.Kandeliik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kandeliik))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kandeliik_tekstina");
            if (clazz.KandeliikTekstina!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandeliikTekstina))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("maaruse_tekst");
            if (clazz.MaaruseTekst!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MaaruseTekst))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="otsuse_number") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ariregistri_toimik_otsus>otsuse_number");
                }
                clazz.OtsuseNumber = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("otsuse_number")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_otsus>otsuse_number", Reader.LocalName);
            }
            if (Reader.LocalName=="otsuse_kpv") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.OtsuseKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("otsuse_kpv")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_otsus>otsuse_kpv", Reader.LocalName);
            }
            if (Reader.LocalName=="otsuse_liik") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.OtsuseLiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("otsuse_liik")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_otsus>otsuse_liik", Reader.LocalName);
            }
            if (Reader.LocalName=="otsuse_liik_tekstina") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.OtsuseLiikTekstina = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("otsuse_liik_tekstina")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_otsus>otsuse_liik_tekstina", Reader.LocalName);
            }
            if (Reader.LocalName=="otsuse_olek") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.OtsuseOlek = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("otsuse_olek")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_otsus>otsuse_olek", Reader.LocalName);
            }
            if (Reader.LocalName=="otsuse_olek_tekstina") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.OtsuseOlekTekstina = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("otsuse_olek_tekstina")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_otsus>otsuse_olek_tekstina", Reader.LocalName);
            }
            if (Reader.LocalName=="joust_kpv") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.JoustKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("joust_kpv")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_otsus>joust_kpv", Reader.LocalName);
            }
            if (Reader.LocalName=="kande_kpv") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.KandeKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("kande_kpv")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_otsus>kande_kpv", Reader.LocalName);
            }
            if (Reader.LocalName=="lisatahtaeg") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Lisatahtaeg = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("lisatahtaeg")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_otsus>lisatahtaeg", Reader.LocalName);
            }
            if (Reader.LocalName=="kandeliik") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Kandeliik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kandeliik")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_otsus>kandeliik", Reader.LocalName);
            }
            if (Reader.LocalName=="kandeliik_tekstina") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.KandeliikTekstina = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kandeliik_tekstina")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_otsus>kandeliik_tekstina", Reader.LocalName);
            }
            if (Reader.LocalName=="maaruse_tekst") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.MaaruseTekst = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("maaruse_tekst")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_otsus>maaruse_tekst", Reader.LocalName);
            }
        }
    }
}
